package com.kidala.pattern;

public class BuilderDemo {

    public static void main(String[] args) {
        Kelner kelner = new Kelner();
        kelner.setPizzaBuilder(new PizzaHawajskaBuilder());
        kelner.utworzPizze();
        Pizza pizza = kelner.getPizza();
        System.out.println(pizza);
    }

}

class Kelner {

    private PizzaBuilder pizzaBuilder;

    public void utworzPizze() {
        getPizzaBuilder().createNewPizza();
        getPizzaBuilder().buildCiasto();
        getPizzaBuilder().buildSos();
        getPizzaBuilder().buildDodatki();
    }

    /**
     * @return the pizza
     */
    public Pizza getPizza() {
        return getPizzaBuilder().getPizza();
    }

    /**
     * @param pizzaBuilder the pizzaBuilder to set
     */
    public void setPizzaBuilder(PizzaBuilder pizzaBuilder) {
        this.pizzaBuilder = pizzaBuilder;
    }

    /**
     * @return the pizzaBuilder
     */
    public PizzaBuilder getPizzaBuilder() {
        return pizzaBuilder;
    }

}

class PizzaHawajskaBuilder extends PizzaBuilder {

    @Override
    public void buildCiasto() {
        pizza.setCiasto("Ciasto sredniej grubosci");
    }

    @Override
    public void buildDodatki() {
        pizza.setSos("Sos pomidorowy");
    }

    @Override
    public void buildSos() {
        pizza.setDodatki("Dodajemy ananasy i szynke");
    }

}

abstract class PizzaBuilder {

    protected Pizza pizza;

    public Pizza getPizza() {
        return pizza;
    }

    public void createNewPizza() {
        pizza = new Pizza();
    }

    public abstract void buildCiasto();
    public abstract void buildSos();
    public abstract void buildDodatki();

}


class Pizza {

    private String ciasto;
    private String sos;
    private String dodatki;

    public String getCiasto() {
        return ciasto;
    }
    public void setCiasto(String ciasto) {
        this.ciasto = ciasto;
    }
    public String getSos() {
        return sos;
    }
    public void setSos(String sos) {
        this.sos = sos;
    }
    public String getDodatki() {
        return dodatki;
    }
    public void setDodatki(String dodatki) {
        this.dodatki = dodatki;
    }

    @Override
    public String toString() {
        return ciasto + ", " + sos + ", " + dodatki;
    }

}

